home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / rvga01.zip / T_EXP-02.C < prev    next >
C/C++ Source or Header  |  1994-08-10  |  3KB  |  131 lines

  1. /**********************************************
  2.  
  3.     Example #02 for the Reglage VGA-Library
  4.  
  5.         TEXT MODE
  6.         Screen Experimenting
  7.  
  8.     V1.0 - Reglage (C) 1994
  9.  
  10. **********************************************/
  11.  
  12. #include <math.h>    //    For the sinetable Calculus
  13.                         //    This really should be precalculated!
  14.  
  15. #include "Keyb.h"
  16. #include "VGA.h"
  17. #include "VGA_T.h"
  18.  
  19. #include "CooLogo.c"                //    The c00l Logotype! Don't forget! :-)
  20.  
  21.  
  22. /**********************************************
  23.  
  24.     main() ... Just a little test!
  25.  
  26. **********************************************/
  27.  
  28. int main(void)
  29. {
  30.     struct Palette OldPalette[16];
  31.     struct Palette NewPalette[16]=
  32.     {
  33.         { 0x00,0x00,0x00 },
  34.         { 0x08,0x00,0x1c },
  35.         { 0x00,0x1c,0x08 },
  36.         { 0x08,0x18,0x1c },
  37.         { 0x20,0x00,0x00 },
  38.         { 0x1c,0x04,0x1c },
  39.         { 0x20,0x14,0x18 },
  40.         { 0x1a,0x1a,0x1a },
  41.         { 0x0e,0x0e,0x0e },
  42.         { 0x08,0x18,0x3f },
  43.         { 0x00,0x3a,0x00 },
  44.         { 0x00,0x3a,0x3a },
  45.         { 0x3a,0x00,0x00 },
  46.         { 0x3f,0x00,0x30 },
  47.         { 0x3f,0x38,0x10 },
  48.         { 0x3f,0x3f,0x3f }
  49.     };
  50.  
  51.     UBYTE sinetable[256];    //    Length 256, Amplitude 256 (0-255)
  52.     UWORD i,x,y,sp=1,xcnt,ycnt;
  53.     int x1,x2,y1,y2;
  54.  
  55.     V_SetMode(3);                        // Set TextMode 80X25
  56.  
  57.     for(i=0;i<256;i++)                //    Create sinetable
  58.         sinetable[i]=(128.0*sin(i*4.41786466898438/180)+127)+0.5;
  59.  
  60.     for(i=0;i<16;i++)
  61.     {
  62.         T_GetPal(i,&OldPalette[i]);//    Store Old Palette
  63.         T_SetPal(i,&NewPalette[i]);//    Setup New Palette
  64.     }
  65.  
  66.     T_SetCursor(0);                    //    Set Cursor Invisible
  67.     T_ClearScreen(0);                    //    Clear ALL Screen Memory
  68.     T_ScreenWidth(80*3);                //    Set Physical Screen Width to 3*80
  69.     T_ScreenOffset(80);                //    Center Visual Screen on the 2nd
  70.                                             //    Physical Screen
  71.  
  72.     for(x=0;x<COOLOGO_WIDTH;x++)    //    Move the COOLOGO to the Screen
  73.         for(y=0;y<(COOLOGO_DEPTH);y++)
  74.             T_screen[(y+25)*T_width+x+96]=COOLOGO[(x+y*COOLOGO_WIDTH)*2]+(COOLOGO[(x+y*COOLOGO_WIDTH)*2+1]<<8);
  75.  
  76.     K_EatKbHit();                        //    Eat Keypress
  77.  
  78.     x1=x2=y1=y2=0;
  79.     xcnt=0;                                //    SinPointer
  80.     ycnt=256/4;                            //    CosPointer
  81.  
  82.     while(K_KbHit())                    //    Continue while no keypresses
  83.     {
  84.         xcnt+=sp;                        //    Increase SinPointer
  85.         ycnt+=sp;                        //    Increase CosPointer
  86.         xcnt&=255;                        //    If>255then-256
  87.         ycnt&=255;                        //    If>255then-256
  88.         x=sinetable[xcnt]*5.625+0.5;    //    Constant Multiplied is 160/256*9
  89.         y=sinetable[ycnt]*3.125+0.5;    //    Constant Multiplied is 50/256*16
  90.  
  91.         x/=4;                                    //    Divide Horizontal Amplitude by 4
  92.         x1=x/9+62;                                //    ...thus Adding 62 to Horizontal Pos
  93.         x2=x%9;                                //    Fine Value Calculated
  94.         x2=--x2<0?8:x2;                    //    Fine Value Corrected due to VGA Stuff
  95.  
  96.         y/=2;
  97.         y1=((y/16)+6)*T_width;
  98.         y2=y&15;
  99.  
  100.         asm cli;                                //    Wait for Beginning of Vertical Blanking
  101.         asm    mov    dx,0x3da;
  102. W1:
  103.         asm    in        al,dx;
  104.         asm    test    al,8;
  105.         asm    jnz    W1;
  106.  
  107.         T_ScreenOffset(x1+y1);            //    Set Appropriate Scrolling Values
  108.         T_HorizontalFine(x2);            //    Set HorizontalFine WHILE VB!
  109.  
  110.         asm    mov    dx,0x3da;            //    Wait for Vertical Blanking to End
  111. W2:
  112.         asm    in        al,dx;
  113.         asm    test    al,8;
  114.         asm    jz        W2;
  115.         asm sti;
  116.  
  117.         V_VerticalFine(y2);                //    Set VerticalFine AFTER VB!
  118.     }
  119.  
  120.     K_EatKbHit();                        //    Eat Keypress
  121.  
  122.     for(i=0;i<16;i++)
  123.     {
  124.         T_SetPal(i,&OldPalette[i]);//    Restore Original Palette
  125.     }
  126.  
  127.     V_SetMode(3);                        // Set TextMode 80X25
  128.  
  129.     return 0;
  130. }
  131.